package com.dove.config.rabbit;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/***
 * 创建队列名，交换机，以及绑定
 */
@Configuration
public class SuccessMqConfig {


    /**
     * true ：队列持久化,mq系统即使重启，队列无需重新创建 ，false：消息非持久化,当mq系统进程关闭，该队列则消失
     * @return
     */

    @Bean
    Queue successMqQueue() {
        return new Queue("successMqQueue", true);
    }

    /**
     * 该构造方法 exchange的 durable=true 则 未消费的消息仍然再重启后可继续被消费 即 消息持久化
     * @return
     */

    @Bean
    DirectExchange successMqQueueExchange(){
        return new DirectExchange("successMqQueueExchange");
    }



    @Bean
    Binding successMqQueueBinding(@Qualifier("successMqQueue")Queue queue, @Qualifier("successMqQueueExchange") DirectExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("successMqQueue");
    }




}